<?php
namespace catchAdmin\mbqy\controller;

use catcher\CatchResponse;
use catcher\base\CatchRequest;
use catcher\base\CatchController;
use app\common\model\ServiceItem as ServiceItemModel;
use app\common\utils\Uniquecode;
use catchAdmin\mbqy\request\SaveRequest;

class Fwitems extends CatchController
{
    protected $serviceItem;

    public function __construct(ServiceItemModel $serviceItem)
    {
        $this->serviceItem = $serviceItem;
    }

    /**
     * 列表
     *
     * @time 2020年01月09日
     * @param CatchRequest $request
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function index(): \think\response\Json
    {
        return CatchResponse::paginate($this->serviceItem->getList());
    }

    /**
     * 保存
     *
     * @time 2020年01月09日
     * @param SaveRequest $request
     * @return \think\response\Json
     */
    public function save(SaveRequest $request): \think\response\Json
    {
        $param = $request->param();
        $param['unique_no'] = uniqid('FWX');
        return CatchResponse::success($this->serviceItem->addData($param));
    }

    /**
     * 更新回显数据
     * @param $id
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function get_up_data($id): \think\response\Json
    {
        return CatchResponse::success($this->serviceItem->getWhereId($id));
    }

    /**
     * 更新
     *
     * @time 2020年01月09日
     * @param $id
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function update($id, SaveRequest $request): \think\response\Json
    {
        return CatchResponse::success($this->serviceItem->saveData($id, $request->param()));
    }

    /**
     * 删除
     *
     * @time 2020年01月09日
     * @param $id
     * @return \think\response\Json
     */
    public function delete(CatchRequest $request): \think\response\Json
    {
        return CatchResponse::success((new ServiceItemModel)->del($request->param()));
    }

    /**
     * 获取全部数据
     * @return \think\response\Json
     */
    public function getfwitems(): \think\response\Json
    {
        return CatchResponse::success($this->serviceItem->getRows());
    }
}